package com.aoxin.controller.course.webCourse;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.aoxin.model.SlfSystemMessage;
import com.aoxin.service.inter.course.webCourse.SystemMessageService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.EmptyUtil;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

@RestController
@RequestMapping("/web/systemMessage/")
public class SystemMessageController {

	@Autowired
	SystemMessageService systemMessageService;

	/**
	 * 新增系统信息
	 * 
	 * @param slfSystemMessage
	 * @param res
	 * @return
	 */
	@RequestMapping("insertSystemMessage")
	@LogInfo(content = "系统消息", operateType = OperateType.INSERT)
	public AjaxRes insertSystemMessage(SlfSystemMessage slfSystemMessage, @RequestParam("userIds") List<Integer> userIds, AjaxRes res) {
		try {
			if (!EmptyUtil.objFieldsIsEmpty(slfSystemMessage)) {
				Integer result = systemMessageService.insertSystemMessage(slfSystemMessage, userIds);
				if (result != 0) {
					res.setSucceedMsg("insertSystemMessage success!");
				} else {
					res.setFailMsg("insertSystemMessage Fail!");
				}
			} else {
				res.setFailMsg("slfSystemMessage is null");
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return res;
	}

	/**
	 * 查询系统信息
	 * 
	 * @param slfSystemMessage
	 * @param res
	 * @return
	 */
	@RequestMapping("getSystemMessage")
	/* @LogInfo(content = "系统消息",operateType = OperateType.QUERY) */
	public AjaxRes getSystemMessage(SlfSystemMessage slfSystemMessage, AjaxRes res) {
		List<SlfSystemMessage> slfSystemMessagePageInfo = systemMessageService.getSystemMessage(slfSystemMessage);
		res.setSucceed(slfSystemMessagePageInfo, "getClassChildren success!");
		return res;
	}

	/**
	 * （批量）删除系统消息
	 * 
	 * @param messageIds
	 * @param res
	 * @return
	 */
	@RequestMapping("deleteSystemMessage")
	/* @LogInfo(content = "系统消息",operateType = OperateType.DELETE) */
	public AjaxRes deleteSystemMessage(@RequestParam("messageIds") List<Integer> messageIds, AjaxRes res) {
		if (messageIds != null && messageIds.size() > 0) {
			Integer result = systemMessageService.deleteSystemMessage(messageIds);
			if (result != 0) {
				res.setSucceedMsg("deleteSystemMessage success!");
			} else {
				res.setFailMsg("deleteSystemMessage Fail!");
			}
		} else {
			res.setFailMsg("messageIds is null!");
		}
		return res;
	}

	/**
	 * 修改系统消息
	 * 
	 * @param slfSystemMessage
	 * @param res
	 * @return
	 */
	@RequestMapping("updateSystemMessage")
	/* @LogInfo(content = "系统消息",operateType = OperateType.UPDATE) */
	public AjaxRes updateSystemMessage(SlfSystemMessage slfSystemMessage, AjaxRes res) {
		try {
			if (!EmptyUtil.objFieldsIsEmpty(slfSystemMessage)) {
				Integer result = systemMessageService.updateSystemMessage(slfSystemMessage);
				if (result != 0) {
					res.setSucceedMsg("updateSystemMessage success!");
				} else {
					res.setFailMsg("updateSystemMessage Fail!");
				}
			} else {
				res.setFailMsg("slfSystemMessage is null!");
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return res;
	}

	/**
	 * 发送系统信息
	 * 
	 * @param slfSystemMessage
	 * @param res
	 * @return
	 */
	@RequestMapping("sendSystemMessage")
	/* @LogInfo(content = "系统消息",operateType = OperateType.INSERT) */
	public AjaxRes sendSystemMessage(SlfSystemMessage slfSystemMessage, AjaxRes res) {
		try {
			if (!EmptyUtil.objFieldsIsEmpty(slfSystemMessage)) {
				Integer result = systemMessageService.sendSystemMessage(slfSystemMessage);
				if (result != 0) {
					res.setSucceedMsg("sendSystemMessage success!");
				} else {
					res.setFailMsg("sendSystemMessage Fail!");
				}
			} else {
				res.setFailMsg("slfSystemMessage is null");
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return res;
	}

}
